<template>
	<uni-popup ref="popup" type="bottom" @change="changePop">
		<view class="content column">
			<text class="mix-icon icon-guanbi" @click="close"></text>
			<view class="pro-info row">
				<image   class="pic" :src="message.pic" mode=""></image>
				<view class="right column">
					<view class="text">
						{{message.prodName}}
					</view>
					<view class="price">
						{{message.price}} 元
					</view>
				</view>
			</view> 
				<!-- 规格 -->
			<scroll-view class="c-wrap" scroll-y="true">
				<view class="sku-list fill">
					<view v-for="(item, index) in skuList" :key="index">
						<text class="s-tit">{{ item.value }}</text>
						<!-- 规格值 -->
						<view class="attrs">
							<view 
								class="attr round center" 
								:class="{active: currentSku==aIndex, disabled: aItem.disabled}"
								v-for="(aItem, aIndex) in item.detail" 
								:key="aIndex"
								@click="chooseAttr(aIndex, aItem,item.value)"
							>
								<text>{{ aItem}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="number-wrap row">
					<text class="s-tit fill">数量</text>
					<!-- <mix-number-box :value="buyNumber" :min="1" :max="currentSku.stock || 999" @eventChange="onNumberChange"></mix-number-box> -->
					<button class="btn" type="default" @click="count>1&&count--">-</button>
					<input type="text" class="inp" v-model="count" />
					<button class="btn" type="default" @click="count<10&&count++">+</button>
				</view>
			</scroll-view>
			<view class="btn-wrap row">
			<!-- 	<view  class="confirm-btn center" @click="confirm">
					<text>确认</text>
				</view> -->
				<view  class="sm row" > 
					<view class="btn center" @click="confirm('cart')">
						<text>加入购物车</text>
					</view>
					<view class="btn center" @click="confirm('buy')">
						<text>立即购买</text>
					</view>
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	export default {
	 components: {
			uniPopup
		},
		data() {
			return {
				count:1,//数量
				currentSku:"0",
				skuList:[],
				title:'',
				message:''
			}
		},
		
		props: {
			infoData: {
				type: Object,
				default(){
					return {
						
					}
				}
			},
			value:{
				type: Boolean
			},
			data:{
				type: Object,
			}
			
		},
		watch:{
			value(news){
				if(news){
					this.$refs.popup.open()
					// this.skuList = this.infoData.attr
					// this.title=this.skuList[0].value+':' +this.skuList[this.currentSku].detail
				}
			}
		},
	
		methods: {
			chooseAttr(index,item,type){
				this.currentSku = index
			},
			changePop(e){
				console.log(this.message = this.data)
				this.$emit('setSize',this.title)	
				if(e.show == false){
					this.$emit('input',false)	
				}
			},
			close(){
				console.log('关闭1')
				this.$refs.popup.close();
				this.$emit('input',false)
			},
			async confirm(type){
				if(type == 'buy'){
					console.log('点击购买')
					console.log(this.message)
					var message = JSON.stringify(this.message)
					this.$u.route({
						url: '/Shop/payment/payment?message='+message
					})
					this.$refs.popup.close();
					this.$emit('input',false);
				}else{
					console.log('添加购物车')
				}
				// if(!uni.getStorageSync("UserInfo")){
				// 	this.navTo("/pages/logoin/login")
				// 	uni.showToast({
				// 		title:"请先登录"
				// 	})
				// 	return;
				// 	// 添加购物车
				// }else if(type=="cart"){
				// 	console.log('添加购物车');
				// }else if(type=="buy"){
					
					
				// this.data.totle=this.data.price*this.count
				// this.data.title=this.title,
				// this.data.count=this.count
				// console.log(this.data);
				// 	// 添加订单
				// 	uni.navigateTo({
				// 			url: "/pagesA/payment/payment?data=" + encodeURIComponent(JSON.stringify(this.data))
				// 		})
				
				// }
				
				
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.content{
		width: 750rpx;
		background-color: #fff;
		border-radius: 10rpx 10rpx 0 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom); 
		position: relative;
	}
	.icon-guanbi{
		position: absolute;
		right: 10rpx;
		top: 10rpx;
		padding: 20rpx;
		font-size: 32rpx;
		color: #999;
	}
	.pro-info{
		padding: 30rpx 32rpx 16rpx;
		
		.pic{
			flex-shrink: 0;
			width: 160rpx;
			height: 160rpx;
			margin-right: 20rpx;
			background-color: #f7f7f7;
			border-radius: 10rpx;
		}
		.text{
			font-weight: 550;
			font-size: 36rpx;
		}
		.price{
			padding-top: 10rpx;
			margin-bottom: 26rpx;
			font-size: 34rpx;
			color:#F71205 ;
			font-weight: 700;
		}
		.stock{
			margin-bottom: 20rpx;
			font-size: 24rpx;
			color: #999;
		}
		.attr-wrap{
			flex-wrap: wrap;
			
			text{
				line-height: 1.4;
				font-size: 24rpx;
				color: #333;
			}
			.attr{
				flex-shrink: 0;
				margin-right: 10rpx;
				color: #999;
				
				&.checked{
					color: #333;
				}
			}
		}
	}
	.s-tit{
		margin-left: 42rpx;
		font-size: 30rpx;
		color: #333;
		font-weight: 700;
		line-height: 90rpx;
	}
	.c-wrap{
		min-height: 20vh;
		max-height: 60vh;
	}
	.sku-list{
		.attrs{
			display: flex;
			flex-wrap: wrap;
			padding-left: 32rpx;
			padding-right: 20rpx;
		}
		.attr{
			min-width: 58rpx;
			height: 58rpx;
			padding: 0 24rpx;
			margin-right: 20rpx;
			margin-bottom: 20rpx;
			font-size: 26rpx;
			color: #333;
			
			&:after{
				border-color: #e0e0e0;
			}
			&.active{
				color:#ff007f;
				background-color: rgba(255, 82, 111, .03);
			
				&:after{
					border-color: rgba(255, 82, 111, .5);
				}
			}
			&.disabled{
				background-color: #ddd;
			}
		}
	}
	.number-wrap{
		padding-right: 40rpx;
		
		.inp{
			width: 80rpx;
			text-align: center;
		}
			.btn{
				margin: 0 10rpx;
				line-height: 60rpx;
				width: 60rpx;
				height: 60rpx;
				background-color: #cccccc;
			}
	}
	.btn-wrap{
		align-items: flex-end;
		justify-content: center;
		padding: 36rpx 0 30rpx;
	}
	.confirm-btn{
		width: 670rpx;
		height: 84rpx;
		background-color: #ff007f;
		font-size: 32rpx;
		color: #fff;
		border-radius: 100rpx;
	}
	.sm{
		width: 670rpx;
		margin: 0 auto;
		
		.btn{
			flex: 1;
			height: 84rpx;
			font-size: 32rpx;
			color: #fff;
			background-color: orange;
			border-radius: 100rpx 0 0 100rpx;
			
			&:last-child{
				background-color: #ff007f;
				border-radius: 0 100rpx 100rpx 0;
			}
		}
	}
</style>
